package cn.lixufeng.user.controller;

import cn.lixufeng.basic.exception.BusinessException;
import cn.lixufeng.basic.utils.AjaxResult;
import cn.lixufeng.user.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService iVerifyCodeService;

    /**
     * 发送验证码
     * 在某些情况且前端传的参数很少的时候，可以用Map对象接收参数
     * @param param
     * @return
     */
    @PostMapping("/sendVerifycode")
    public AjaxResult sendVerifycode(@RequestBody Map<String,String> param){
        try {
            iVerifyCodeService.sendVerifyCode(param);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统繁忙，请稍后再试！");
        }

    }

}
